// pages/todayStop/todayStop.js
let app = getApp();
let util = require("../../utils/util");
import { getTicketsSaleListApi } from "../../api/index.js";

Page({
  /**
   * 页面的初始数据
   */
  data: {
    pageAllHeight: app.globalData.pageAllHeight,
    saleRecordInfo: {
      dayList:['1']
    },
    firstAndLastTime: util.getFirstAndLastDay(),
    gid: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    if(options.gid) {
      this.setData({
        gid:options.gid
      })
      this.getTicketsSaleList();
    }
    
  },
  // 选择月份
  changeDate(e) {
    const { detail } = e;
    this.setData({
      'firstAndLastTime.startTime':detail.startTimestamp,
      'firstAndLastTime.endTime':detail.endTimestamp
    })
    this.getTicketsSaleList();
  },

  //  查询出售明细
  async getTicketsSaleList() {
    console.log(this.data.firstAndLastTime);
    const {startTime,endTime} = this.data.firstAndLastTime;
    const { gid } = this.data;
    try {
      const { data: res } = await getTicketsSaleListApi({ gid,startTime,endTime });
      console.log(res);
      this.setData({
        saleRecordInfo:res.data
      })
    } catch (error) {
      console.log(error);
    }
  },
});
